<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/6/27 10:50
 * Modified Time: 2019/6/27 10:50
 * Version: 2.0
 */

namespace App\Models;


use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class Service extends Model
{

    use SoftDeletes;

    protected $table = 'store_service';

    protected $primaryKey = 'id';

    protected $datas = ['deleted_at'];

    protected $guarded = [
        'created_at',
        'deleted_at',
    ];


    public function userRoyalty(){
    	return $this->hasMany(UserRoyalty::class,'service_id','id');
    }


	public function scopeUserRoyaltyByUserId(Builder $query,$userId,$storeId){
		return $query->has('userRoyalty','and',function($q) use($userId,$storeId){
			$q->where(['user_id'=>$userId,'store_id'=>$storeId]);
		}
		);
	}

	public function dictionaryItem(){
//    	return $this->hasOne(DictionaryItem::class,$);
	}
}